<template>
	<view>
		<web-view v-if="pageSrc.length" :src="pageSrc"></web-view>
		<tb-privacy ref="prcy" :onNeed='true'></tb-privacy>
	</view>

</template>

<script lang="ts" setup>
	import { ref } from 'vue';
	import { onShow, onUnload, onLoad, onShareAppMessage } from '@dcloudio/uni-app';
	import { env } from '@/api/env.js'
	import global from '@/utils/global'
	import { useShopStore } from '@/stores/shopStore';
	import { useUserStore } from '@/stores/commonStore';
	import { takeSaveShare, initShop } from '@/utils/public';
	import { mnavTo } from '@/utils/helper';
	import { getSpecialScopes, modifyScopeShopDetails, getSpecialDetails, getShareDetail, queryMemberList } from '@/api/vmeitime-http/index.js'
	import { checkOrg } from '@/utils/helper';
	import mapi from '@/utils/mapi';
	// import mapi from '@/utils/mapi';
	const shopStore = useShopStore()
	const userStore = useUserStore()
	const pageSrc = ref()
	const specialId = ref()
	const dataList = ref<any>()
	const userInfo = ref()
	const n_memberId = ref()
	const shareObj = ref()
	const shareId = ref()
	const pageNeedGps = ref(false)
	const optionSence = ref()
	const sellerMemberId = ref()
	const pageLoaded = ref(false)
	const newExpiration = ref()
	const Timestamp = ref()
	const imgUlr = ref(env.imgBaseUrl)
	const isQrCome = ref(false)
	const specialEventId = ref()
	const isToSetting = ref(false)
	const reqParams = ref<any>({})
	const matchType = ref()//是否限制活动范围913为所有门店，914指定范围
	const actScope = ref()//活动范围
	const defaultShop = ref()
	const optionShopId = ref()
	const isNeedChange = ref(false)
	const advertorial = ref(false)
	const isCardShare = ref(false)
	const isToLogin = ref(false)
	const isDefaultLogin = ref(false)
	const tiket = ref()
	const consumActivityId = ref()//码活动id
	const consumCode = ref()//码code
	const ntemplateId = ref()//模板ID
	const codeCanGet = ref()
	const setted = ref(false)
	const isshareAct = ref()
	const prcy = ref()
	const shopData = ref()
	const tdataList = ref<any>()
	const hasPageSrc = ref()

	onLoad((options) => {
		uni.hideShareMenu()//关闭分享
		pageSrc.value = '';
		// 消费代金券跳转携带参数-s
		consumActivityId.value = options.consumActivityId || ''
		codeCanGet.value = options.codeCanGet || ''
		consumCode.value = options.consumCode || ''
		// 消费代金券跳转携带参数-e
		specialEventId.value = options.event_id || '';
		defaultShop.value = shopStore.shopInfo || {};
		optionShopId.value = options.sell_member_id || '';
		let firstSMemberId = (optionShopId.value && optionShopId.value == defaultShop.value.nmember_id) ? optionShopId.value : '';
		sellerMemberId.value = firstSMemberId ? firstSMemberId : '';
		if (consumActivityId.value && options.sell_member_id) {
			sellerMemberId.value = options.sell_member_id
		}
		userInfo.value = userStore.userInfo || {};
		specialId.value = options.specialId || '';
		advertorial.value = options.advertorial || '';
		if (options.scene) {
			optionSence.value = options.scene;
			isQrCome.value = true;
			getShareDetail({ share_id: options.scene })
				.then((res) => {
					console.log('小程序码进入获取参数', res);
					if (res.result) {
						var request_params = JSON.parse(res.object.request_params);
						reqParams.value = request_params || {};
						console.log('request_params获取分享码参数:', request_params);
						let sellerMemberId = request_params.sell_member_id || '';
						sellerMemberId.value = sellerMemberId || '';
						shopStore.setQrShop(sellerMemberId)
						// uni.setStorageSync(this.$global.QR_PARENT_MEMBERID, request_params.buy_member_id || '');
						// et memberId = request_params.buy_member_id?request_params.buy_member_id:(this.userInfo.memberId||'')
						let memberId = request_params.buy_member_id ? request_params.buy_member_id : ''
						this.n_memberId = memberId;
						let qrshareId = res.object.share_id || '';
						// var qrEventId = uni.getStorageSync(this.$global.QR_NEW_MEAL_EVENT_ID)||{};
						specialEventId.value = request_params.event_id || '';
						// console.log("submitShareEventId_Data2:"+JSON.stringify(qrEventId))
						specialId.value = request_params.source_type || '';
						if (sellerMemberId) {
							// this.submitEventIdSync(this.reqParams);
							// this.saveCardShare(this);//7++
							isCardShare.value = true;
							modifyShopDetail();
						} else {
							// this.getRelocateGps();
							getSpecialScope('locGbs');
						}
					}
				})
				.catch(err => {
					// this.getSpecial();
					// this.pageSrc = env.specalModalUrl + '?sellerMemberId=' + sellerMemberId + '&specialId='+this.specialId +'&memberId=' + memberId + '&'+Timestamp;
					// this.getShareId(memberId,sellerMemberId);
					console.log('获取小程序码进入首页信息失败', err);
				});
		} else if (options.shareScene) {
			optionSence.value = options.shareScene;
			isQrCome.value = true;
			getShareDetail({ share_id: options.shareScene })
				.then((res) => {
					if (res.result) {
						var request_params = JSON.parse(res.object.request_params);
						console.log('request_params获取分享码参数:', request_params);
						reqParams.value = request_params || {};
						let memberId = request_params.buy_member_id ? request_params.buy_member_id : '';
						n_memberId.value = memberId;
						let qrshareId = res.object.share_id || '';
						specialEventId.value = request_params.event_id;
						specialId.value = request_params.source_type || '';

						if (request_params.sell_member_id && request_params.sell_member_id == '17396') {
							sellerMemberId.value = request_params.sell_member_id;
							shopStore.setQrShop(sellerMemberId.value)
							this.modifyShopDetail();
							isCardShare.value = true;
							return
						}
						determineLoad('shareScene')
					}
				})
				.catch(err => {
					// this.getSpecial();
					// this.pageSrc = env.specalModalUrl + '?sellerMemberId=' + sellerMemberId + '&specialId='+this.specialId +'&memberId=' + memberId + '&'+Timestamp;
					// this.getShareId(memberId,sellerMemberId);
					console.log('获取分享进入专题页信息失败', err);
				});
		} else {
			//2020-12-17专题分享 默认卖家活动->若无活动则自动定位到最近卖家
			determineLoad()
		}

	})
	const determineLoad = (source = '', selMemberId = '') => {
		let sellerMemberIds = selMemberId || sellerMemberId.value || '';
		let qrSmemberId = shopStore.qrsellerMemberId
		var defaultShopId = qrSmemberId ? qrSmemberId : defaultShop.value.nmember_id || '';//9-8
		if (defaultShopId && source == 'shareScene') {
			shopStore.setQrShop(defaultShopId)
		}
		if (!sellerMemberId) {
			if (defaultShopId && !advertorial.value) {
				getSpecialDetails({ specialId: specialId.value, nsell_member_id: defaultShopId })
					.then((res) => {
						if (!res.result || !res.object) {
							uni.showModal({
								title: '提示',
								confirmColor: '#2CAD8D',
								content: optionShopId.value && optionShopId.value != defaultShopId ? '当前门店未发现此活动，是否切换到指定门店' : '该门店没有活动，是否切换到最近活动门店',
								success: function (res) {
									if (res.confirm) {
										isNeedChange.value = true;
										console.log('用户点击确定');
										// that.optionShopId&&that.optionShopId!=defaultShopId?that.sellerMemberId=that.optionShopId&&that.modifyShopDetail('','','locGbs'):that.getSpecialScope('changeM');
										if (optionShopId.value && optionShopId.value != defaultShopId) {
											sellerMemberId.value = optionShopId.value;
											modifyScopeShopDetail('', '', 'changeM');
										} else {
											getSpecialScope('changeM')
										}
										// that.getSpecialScope('changeM');
										console.log('that.sellerMemberId-that.optionShopId', sellerMemberId.value, optionShopId.value)
									} else if (res.cancel) {
										isNeedChange.value = false;
										// let pages = getCurrentPages();
										// let prevPage = pages[pages.length - 2];
										console.log('用户点击取消share');
										// uni.navigateBack();
										navBack(source)
										// that.getSpecialScope();
									}
								}
							});
							console.log('获取getSpecialDetail失败', res.shortMessage);
							return;
						}

						if (optionShopId.value && optionShopId.value != defaultShopId) {
							uni.showModal({
								title: '提示',
								confirmColor: '#2CAD8D',
								content: '当前门店与指定门店的活动不匹配，是否切换到指定门店',
								success: function (res) {
									if (res.confirm) {
										isNeedChange.value = true;
										sellerMemberId.value = optionShopId.value;
										modifyScopeShopDetail('', '', 'changeM');
									} else if (res.cancel) {
										isNeedChange.value = false;
										console.log('用户点击取消跳转至当前门店活动');
										// uni.navigateBack();
										navBack(source)
									}
								}
							});
						} else {
							let memberId = userInfo.value.memberId || '';
							const Timestamps = Timestamp.value || new Date().getTime();
							n_memberId.value = memberId;
							dataList.value = res.object || {};
							reqParams.value.sell_member_id = defaultShopId;
							reqParams.value.event_id = specialEventId.value;
							let specialKey = dataList.value.ntemplate_id || '';
							let specialEvtId = reqParams.value.event_id || '';
							ntemplateId.value = specialKey;
							sellerMemberId.value = defaultShopId;
							submitEventIdSync(reqParams.value);
							if (memberId) {
								hasPageSrc.value = true
								pageSrc.value = env.specalModalUrl + '?tiket=' + tiket.value + '&ntemplateId=' + ntemplateId.value + '&sellerMemberId=' + defaultShopId + '&specialEvtId=' + specialEvtId + '&specialId=' + specialId.value + '&specialKey=' + specialKey + '&memberId=' + memberId + '&groupMemberType=' + (userInfo.value.groupMemberType || '') + '&consumActivityId=' + consumActivityId.value + '&consumCode=' + consumCode.value + '&codeCanGet=' + codeCanGet.value + '&time=' + Timestamps + '#/specialModal';
								// getShareId(defaultShopId);//8++
								// console.log('linksrc', that.pageSrc)
							} else {
								if (!global.CENTER_LOGIN_PAGE) {
									global.CENTER_LOGIN_PAGE = true; //进入登录页面
									isDefaultLogin.value = true;
									mnavTo(`/pages/login/login`)
								}
								return;
							}
						}
					})
					.catch(err => {
						uni.showModal({
							title: '提示',
							content: '系统正忙，请稍后再试哦',
							confirmText: '知道了',
							confirmColor: '#2CAD8D',
							showCancel: false,
							success(res) {
								if (res.confirm) {
									navBack(source)
								}
							}
						})
						console.log('获取getSpecial失败', err);
					});
			} else {
				if (optionShopId.value) {
					sellerMemberId.value = optionShopId.value;
					modifyScopeShopDetail('', '', 'changeM');
				} else {
					getSpecialScope('changeM');
				}
			}
		} else {
			//理 3-13消费券扫码进入不清除
			if (!consumActivityId.value) {
				shopStore.setQrShop('')
			}
			let memberId = userInfo.value.memberId || '';
			n_memberId.value = memberId;
			// const Timestamp = this.Timestamp||new Date().getTime();
			// this.pageSrc = env.specalModalUrl + '?sellerMemberId=' + sellerMemberId + '&specialId='+this.specialId +'&memberId=' + memberId + '&groupMemberType=' + (this.userInfo.groupMemberType || '') + '&time='+Timestamp+'#/specialModal';
			reqParams.value.sell_member_id = sellerMemberId;
			reqParams.value.event_id = specialEventId.value;
			// this.submitEventIdSync(this.reqParams);
			isCardShare.value ? isCardShare.value = false : '';
			console.log('getLoginYZ_+')
			getLoginYZ();
			// this.getSpecial(sellerMemberId);
			// this.getShareId(sellerMemberId,this.specialEventId);
		}



	}
	const navBack = (source : any = '') => {
		if (source == 'shareScene') {
			uni.switchTab({ url: '/pages/index/home/home' })
		} else {
			uni.navigateBack();
		}
	}
	const modifyShopDetail = (longitude : any = '', latitude : any = '', source : any = '') => {
		queryMemberList({
			longitude: longitude ? longitude : '113.064388',//默认隆平店（因为此页面没定位，首页距离有问题）
			latitude: latitude ? latitude : '28.208595', //默认隆平店（因为此页面没定位，首页距离有问题）
			vtype_two_category: 0,
			vtype: '835',
			vIsFirstShop: '猪会飞',//传值就只有一条数据
			sellShopId: sellerMemberId.value || '',
			curPage: 1,
			pageSize: 200//必须要大于总门店数，后台才能计算距离并排序
		})
			.then((res) => {
				if (!res.result) {
					uni.showToast({
						mask: true,
						title: '网络正忙,请稍后再试哦',
						icon: 'none'
					});
					return;
				}
				var thisShop = res.object || [];
				let array = [];
				for (let key in thisShop) {
					let dist = key.split('.')[0];
					thisShop[key]['distanceUnit'] = dist.length > 3 ? '千米' : '米';
					dist = dist.length > 3 ? (Number(dist) / 1000).toFixed(2) : dist;
					thisShop[key]['distance'] = dist;
					array.push(thisShop[key]);
				}
				shopData.value = array[0];
				shopStore.setLocalTime(new Date().getTime())
				shopStore.setShop(shopData.value)
				let memberId = shopStore.curSellerMemberId || '';
				if (source == 'locGbs') {
					sellerMemberId.value = shopData.value.nmember_id || '';
					reqParams.value.sell_member_id = sellerMemberId.value
					shopStore.setQrShop(sellerMemberId.value || '')
					isCardShare.value = true;
				}
				getLoginYZ()
			})
			.catch(err => {
				uni.showToast({
					mask: true,
					title: '获取门店信息失败！',
					icon: 'none'
				});
				console.log('查询最近门店失败', err);
			});
	}

	onShareAppMessage(() => {
		return new Promise(async (resolve, reject) => {
			let param = {
				event_id: 12, //事件id原event_id||12
				source_type: specialId.value, //1首页分享，2商品分享，3名片分享
				goods_id: '',
				goods_sku: '',
				activity_id: '',
				buy_member_id: n_memberId.value, //用户id
				sell_member_id: sellerMemberId.value //门店id
			}
			try {
				let shareId = await takeSaveShare(param)
				let des = dataList.value.vdesc || '';
				let img = dataList.value.vshare_image ? (imgUlr.value + dataList.value.vshare_image) : '';
				let shareGoodsTitle = dataList.value.vshare ? dataList.value.vshare : '专题活动';
				if (shareId) {
					let msg = {
						title: des,
						content: '',
						path: '/pages/order/goodsDetial/goodsDetial?scene=' + shareId,
						imageUrl: img,
					}
					resolve(msg)
				} else {
					reject('');
					mapi.msg('分享失败,请稍后重试')
				}
			} catch (e) {
				reject('');
				mapi.msg('分享失败,请稍后重试')
				console.error(e)
				//TODO handle the exception
			}

		});
	});
	onShareAppMessage((object : any) => {
		isshareAct.value = true;
		if (object.from == "menu") {//三角形分享(原生态)
			//此处添加
			console.log('objectshare', object);
			let des = dataList.value.vdesc || '';
			let img = dataList.value.vshare_image ? (imgUlr.value + dataList.value.vshare_image) : '';
			let shareGoodsTitle = dataList.value.vshare ? dataList.value.vshare : '专题活动';
			console.log('share', shareGoodsTitle, des, img);
			return shareDetail(shareId.value, shareGoodsTitle, des, img);
		}
		return {}
	})

	onUnload(() => {
		pageSrc.value = ''
	})
	onShow(() => {
		tiket.value = uni.getStorageSync(global.USER_TIKET) || '';
		Timestamp.value = new Date().getTime();
		defaultShop.value && !defaultShop.value.nmember_id ? (defaultShop.value = shopStore.shopInfo || {}) : '';
		if (pageNeedGps.value && dataList.value) {
			console.log('load+=1')
			getSpecialScope();
			// this.getRelocateGps()
		}
		if (pageLoaded.value && !isDefaultLogin.value && shareId.value) {
			console.log('load+=2')
			userInfo.value = userStore.userInfo || {};
			isToLogin.value ? getSpecial() : getLoginYZ();
			return
		}
		if(isDefaultLogin.value){
			console.log('load+=3')
			console.log('分享登录刷新页面')
			isDefaultLogin.value=false;
			const Timestamps = Timestamp.value||new Date().getTime();
			pageSrc.value = env.specalModalUrl + '?tiket='+ tiket.value + '&ntemplateId='+ ntemplateId.value +'&sellerMemberId=' + sellerMemberId.value + '&specialEvtId='+specialEventId.value + '&specialId='+specialId.value +'&specialKey='+dataList.value.ntemplate_id+'&memberId=' + userInfo.value.memberId + '&groupMemberType=' + (userInfo.value.groupMemberType || '') + '&consumActivityId=' + consumActivityId.value + '&consumCode=' + consumCode.value + '&codeCanGet='+ codeCanGet.value + '&time='+Timestamps+'#/specialModal';
			// getShareId(sellerMemberId.value);//8++
			return
		}
		if(hasPageSrc.value&&(ntemplateId.value=='4'||ntemplateId.value=='5'||ntemplateId.value=='6')){
			console.log('load+=4')
			const Timestamps = this.Timestamp||new Date().getTime();
			// const currenSrc = this.pageSrc
			// this.pageSrc = ''
			// this.pageSrc = currenSrc
			pageSrc.value = env.specalModalUrl + '?tiket='+ tiket.value + '&ntemplateId='+ ntemplateId.value +'&sellerMemberId=' + sellerMemberId.value + '&specialEvtId='+specialEventId.value + '&specialId='+specialId.value +'&specialKey='+dataList.value.ntemplate_id+'&memberId=' + userInfo.value.memberId + '&groupMemberType=' + (userInfo.value.groupMemberType || '') + '&consumActivityId=' + consumActivityId.value + '&consumCode=' + consumCode.value + '&codeCanGet='+ codeCanGet.value + '&time='+Timestamps+'#/specialModal';
			// console.log('shua',this.pageSrc)
			// setTimeout(()=>{
			// },60)
		}
	})
	const getSpecialScope = (orType : any = '') => {
		// let that = this;
		prcy.value.checkPrivacySetting()
		getSpecialScopes({ specialId: specialId.value })
			.then((res : any) => {
				console.log('获取获取专题范围', res);
				if (!res.result || !res.object) {
					uni.showModal({
						title: '提示',
						content: '系统正忙，请稍后再试哦',
						confirmText: '知道了',
						confirmColor: '#2CAD8D',
						showCancel: false,
						success(res) {
							if (res.confirm) {
								uni.navigateBack();
							}
						}
					})
					return;
				}
				matchType.value = res.object.vsearch_match_type || '';
				actScope.value = res.object.vscope || '';
				getRelocateGps(orType);
			})
			.catch(err => {
				console.log('获取获取专题范围失败err', err);
			});
	}
	const getRelocateGps = (orType : any = '') => {
		pageNeedGps.value = true;
		uni.authorize({
			scope: 'scope.userLocation',
			success() {
				uni.getLocation({
					//获取当前的位置坐标
					type: 'gcj02', //默认为 wgs84 返回 gps 坐标，gcj02 返回国测局坐标，可用于 uni.openLocation 的坐标
					success: function (res) {
						console.log('定位获取经纬度', res);
						uni.setStorageSync('firstLongitudeLatitude', res.longitude + ',' + res.latitude);
						uni.setStorageSync('oldLongitudeLatitude', res.longitude + ',' + res.latitude);
						// that.emptyLocation = false;
						modifyScopeShopDetail(res.longitude, res.latitude, orType)
						// that.saveCardShare(that);
					},
					fail: function (result) {
						console.log('定位失败1.1.6', result);
						// that.emptyLocation = true;
						// 成功调用授权窗口
						wx.getSetting({
							//获取用户的当前设置，返回值中只会出现小程序已经向用户请求过的权限
							success: function (res) {
								var statu = res.authSetting;
								if (!statu["scope.userLocation"]) {
									//3秒
									// that.modalName = 'Image'
									//如果设置中没有位置权限
									wx.showModal({
										//弹窗提示
										title: "授权获取地理位置",
										showCancel: false,//不显示取消
										confirmText: '确认授权',
										confirmColor: '#2CAD8D',
										content: "“颐而康精选” 需要获取您当前位置",
										success: function (tip) {
											if (tip.confirm) {
												isToSetting.value = true;
												wx.openSetting({
													//点击确定则调其用户设置
													success: function (data) {
														if (data.authSetting["scope.userLocation"] === true) {
															//如果设置成功
															wx.showToast({
																title: "定位授权成功",
																icon: "success",
																duration: 1000
															});
															uni.getLocation({
																type: 'gcj02', //默认为 wgs84 返回 gps 坐标，gcj02 返回国测局坐标，可用于 uni.openLocation 的坐标
																success(res) {
																	console.log('定位获取经纬度', res);
																	uni.setStorageSync('firstLongitudeLatitude', res.longitude + ',' + res.latitude);
																	uni.setStorageSync('oldLongitudeLatitude', res.longitude + ',' + res.latitude);
																	modifyScopeShopDetail(res.longitude, res.latitude, orType);
																	// that.saveCardShare(that);
																}
															});
														}
													}
												});
											} else {
											}
										}
									});
								} else {
									// that.showLocalFailed = true;//自定义授权
									wx.showToast({
										title: "定位失败",
										icon: "success",
										duration: 1000
									});
								}
							},
							fail: function (res) {
								wx.showToast({
									title: "调用授权定位失败",
									icon: "success",
									duration: 1000
								});
								return
							},
						});
						//2020-3-24修改定位授权 tosetting方法转移（暂恢复）==>
					}
				});
			},
			fail() {
				if (setted.value) {
					let ndefaultShop = shopStore.shopInfo || {};
					sellerMemberId.value = ndefaultShop.nmember_id || '';
					modifyScopeShopDetail('', '', orType)
					return
				}
				wx.getSetting({
					//获取用户的当前设置，返回值中只会出现小程序已经向用户请求过的权限
					success: function (res) {
						setted.value = true
						var statu = res.authSetting;
						if (!statu["scope.userLocation"]) {
							//3秒
							// that.modalName = 'Image'
							//如果设置中没有位置权限
							wx.showModal({
								//弹窗提示
								title: "授权获取地理位置",
								showCancel: false,//不显示取消
								confirmText: '确认授权',
								confirmColor: '#2CAD8D',
								content: "“颐而康精选” 需要获取您当前位置",
								success: function (tip) {
									if (tip.confirm) {
										isToSetting.value = true;
										wx.openSetting({
											//点击确定则调其用户设置
											success: function (data) {
												if (data.authSetting["scope.userLocation"] === true) {
													//如果设置成功
													wx.showToast({
														title: "定位授权成功",
														icon: "success",
														duration: 1000
													});
													uni.getLocation({
														type: 'gcj02', //默认为 wgs84 返回 gps 坐标，gcj02 返回国测局坐标，可用于 uni.openLocation 的坐标
														success(res) {
															console.log('定位获取经纬度', res);
															uni.setStorageSync('firstLongitudeLatitude', res.longitude + ',' + res.latitude);
															uni.setStorageSync('oldLongitudeLatitude', res.longitude + ',' + res.latitude);
															modifyScopeShopDetail(res.longitude, res.latitude, orType);
															// that.saveCardShare(that);
														}
													});
												}
											}
										});
									} else {

									}
								}
							});
						} else {
							// that.showLocalFailed = true;//自定义授权
							wx.showToast({
								title: "定位失败",
								icon: "success",
								duration: 1000
							});
						}
					},
					fail: function (res) {
						wx.showToast({
							title: "调用授权定位失败",
							icon: "success",
							duration: 1000
						});
						return
					},
				});
			}
		})
	}
	const modifyScopeShopDetail = (longitude : any = '', latitude : any = '', source : any = '') => {
		let shopDat = {
			longitude: longitude ? longitude : '113.064388',//默认隆平店（因为此页面没定位，首页距离有问题）
			latitude: latitude ? latitude : '28.208595', //默认隆平店（因为此页面没定位，首页距离有问题）
			vtype_two_category: 0,
			vtype: '835',
			vIsFirstShop: '猪会飞',//传值就只有一条数据
			sellShopId: sellerMemberId.value || '',
			limitSellMemberId: '',
			curPage: 1,
			pageSize: 200//必须要大于总门店数，后台才能计算距离并排序(德胜说的)
		}
		shopDat.limitSellMemberId = actScope.value || '';
		modifyScopeShopDetails(shopDat)
			.then((res) => {
				if (!res.result) {
					uni.showToast({
						mask: true,
						title: '网络正忙,请稍后再试哦',
						icon: 'none'
					});
					return;
				}
				pageNeedGps.value = false;
				var thisShop = res.object || [];
				let array = [];
				for (let key in thisShop) {
					let dist = key.split('.')[0];
					thisShop[key]['distanceUnit'] = dist.length > 3 ? '千米' : '米';
					dist = dist.length > 3 ? (Number(dist) / 1000).toFixed(2) : dist;
					thisShop[key]['distance'] = dist;
					array.push(thisShop[key]);
				}
				shopData.value = array[0];
				shopStore.setLocalTime(new Date().getTime())
				shopStore.setShop(shopData.value)
				let memberId = shopStore.curSellerMemberId || '';
				if (source == 'locGbs') {
					sellerMemberId.value = shopData.value.nmember_id || '';
					reqParams.value.sell_member_id = sellerMemberId.value
					shopStore.setQrShop(sellerMemberId.value || '')
					isCardShare.value = true;
				}
				getLoginYZ();
			})
			.catch(err => {
				uni.showToast({
					mask: true,
					title: '获取门店信息失败！',
					icon: 'none'
				});
				console.log('查询最近门店失败', err);
			});

	}
	const getLoginYZ = (type : any = '') => {
		getSpecial();//暂
		return
		// that.$request
		// 	.getHeartBeat()
		// 	.then(res => {
		// 		that.pageLoaded = true;
		// 		if (res.code == '-1') {
		// 			that.isToLogin = true;
		// 			console.log('未登录')
		// 		} else {
		// 			that.getSpecial();
		// 		}

		// 	})
		// 	.catch(err => {
		// 		that.pageLoaded = true;
		// 		that.getSpecial();
		// 	});
	}
	const getSpecial = (sellerMemberId : any = '', type : any = '') => {
		var Timestamp = Date.parse(new Date());
		if (reqParams.value) {
			newExpiration.value = Timestamp + 86400000;//缓存24小时 --&& this.reqParams.event_id==8
		}
		getSpecialDetails({ specialId: specialId.value, nsell_member_id: sellerMemberId ? sellerMemberId : sellerMemberId.value })
			.then((res) => {
				console.log('获取getSpecial', res);
				if (!res.result || !res.object) {
					uni.showModal({
						title: '提示',
						content: isQrCome.value ? '未查询到专属活动,去首页逛逛吧' : '门店没有专属活动哦',
						confirmText: isQrCome.value ? '确定' : '知道了',
						confirmColor: '#2CAD8D',
						showCancel: false,
						success(res) {
							if (res.confirm) {
								if (isQrCome.value || consumActivityId.value) {
									uni.switchTab({ url: '/pages/index/home/home' })
								} else {
									uni.navigateBack();
								}
							}
						}
					})
					console.log('获取getSpecialDetail失败', res.shortMessage);
					return;
				}
				dataList.value = res.object || {}
				let specialKey = dataList.value.ntemplate_id || '';
				let specialEvtId = reqParams.value.event_id || '';
				ntemplateId.value = tdataList.value.ntemplate_id || '';
				// ntemplateId.value == '6' ? uni.setNavigationBarTitle({ title: 'VIP专区' }) : '';
				// getShareId();
				hasPageSrc.value = true
				pageSrc.value = env.specalModalUrl + '?tiket=' + tiket.value + '&ntemplateId=' + ntemplateId.value + '&sellerMemberId=' + sellerMemberId.value + '&specialEvtId=' + specialEvtId + '&specialId=' + specialId.value + '&specialKey=' + specialKey + '&expiration=' + newExpiration.value + '&memberId=' + n_memberId.value + '&groupMemberType=' + (userInfo.value.groupMemberType || '') + '&consumActivityId=' + consumActivityId.value + '&consumCode=' + consumCode.value + '&codeCanGet=' + codeCanGet.value + '&time=' + Timestamp + '#/specialModal';
				submitEventIdSync(reqParams.value);
			})
			.catch(err => {
				console.log('获取getSpecial失败', err);
			});
	}
	const submitEventIdSync = async (paramData) => {
		console.log('paramData存', paramData)
		checkOrg(paramData)
	}
	const shareDetail = (shareId : any, shareTitle : any, desc : any, imgSrc : any) => {
		var shareData = {
			title: shareTitle,
			content: desc,
			path: shareId ? '/pages/sys/specialTemplate/specialTemplate?shareScene=' + shareId + '&specialId=' + specialId.value + '&sellerMemberId=' + sellerMemberId.value + '&memberId=' + userInfo.value.memberId : '/pages/index/home/home',
			imageUrl: imgSrc,
			success: function (res) {
				console.log(res)
			},
			fail: function (res) {
				//转发失败后的回调函数
				console.log("分享失败回调函数");
				uni.showToast({
					icon: 'none',
					title: "分享失败"
				})
			}
		}
		return shareData
	}
</script>

<style lang="scss">
page{
	width: 100vw;
	height: 100vh;
}
</style>